﻿using System;
using System.Diagnostics;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKCodeBase.WinForm;
using YJKView;

namespace AreaEdit.AreaShowHide
{
	[Transaction(TransactionMode.Manual)]
	internal class CmdAreaShowHide : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			CmdViewType types = CmdViewType.FloorPlan;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			if (CmdAreaShowHide._hWndRevit == null)
			{
				Process currentProcess = Process.GetCurrentProcess();
				IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
				CmdAreaShowHide._hWndRevit = new WindowHandle(mainWindowHandle);
			}
			try
			{
				CmdAreaShowHide._areaShowHideMag = new AreaShowHideManager(commandData);
				CmdAreaShowHide._areaShowHideMag.Creator();
			}
			catch (Exception)
			{
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

        public static WindowHandle _hWndRevit;

		public static AreaShowHideManager _areaShowHideMag;
	}
}
